Fixed GtkViewport to set adjustments properly for width-for-height widgets
authorTristan Van Berkom <tristan.van.berkom@gmail.com>
Wed, 22 Sep 2010 03:48:37 +0000 (12:48 +0900)
committerTristan Van Berkom <tristan.van.berkom@gmail.com>
Wed, 22 Sep 2010 03:50:06 +0000 (12:50 +0900)
Make GtkViewport calculate widget-for-height as well as height-for-width
cases when setting the scroll adjustment values, also base the scrolling
on the minimum size instead of the natural size in the interest of showing
as much content as possible when the viewport is smaller than the natural
size.

gtk/gtkviewport.c

index 81c40ecc8ffc1c81a79dc7875ebd853f3bcfb26b..644c9b0ece82863d813fcec7dea9268f8471f043 100644 (file)
@@ -49,6 +49,9 @@
  * widget to a #GtkViewport, then add the viewport to the scrolled window.
  * The convenience function gtk_scrolled_window_add_with_viewport() does
  * exactly this, so you can ignore the presence of the viewport.
+ *
+ * The #GtkViewport will start scrolling content only if allocated less
+ * than the child widget's minimum size in a given orientation.
  */
 
 struct _GtkViewportPrivate
@@ -442,11 +445,13 @@ viewport_set_hadjustment_values (GtkViewport *viewport,
   child = gtk_bin_get_child (bin);
   if (child && gtk_widget_get_visible (child))
     {
-      GtkRequisition child_requisition;
+      gint minimum_width;
 
-      gtk_size_request_get_size (GTK_SIZE_REQUEST (child),
-                                 &child_requisition, NULL);
-      hadjustment->upper = MAX (child_requisition.width, view_allocation.width);
+      gtk_size_request_get_width_for_height (GTK_SIZE_REQUEST (child),
+                                             view_allocation.height,
+                                             &minimum_width,
+                                             NULL);
+      hadjustment->upper = MAX (minimum_width, view_allocation.width);
     }
   else
     hadjustment->upper = view_allocation.width;
@@ -482,13 +487,14 @@ viewport_set_vadjustment_values (GtkViewport *viewport,
   child = gtk_bin_get_child (bin);
   if (child && gtk_widget_get_visible (child))
     {
-      gint natural_height;
+      gint minimum_height;
 
       gtk_size_request_get_height_for_width (GTK_SIZE_REQUEST (child),
                                              view_allocation.width,
-                                             NULL,
-                                             &natural_height);
-      vadjustment->upper = MAX (natural_height, view_allocation.height);
+                                             &minimum_height,
+                                             NULL);
+
+      vadjustment->upper = MAX (minimum_height, view_allocation.height);
     }
   else
     vadjustment->upper = view_allocation.height;